import stage from './stage'
const stageConfig = []

Object.keys(stage).forEach((e) => {
  stageConfig.push(stage[e])
})

// 获取所有子节点数据
function deepTravel (config, fuc) {
  if (Array.isArray(config)) {
    config.forEach((subConfig) => {
      deepTravel(subConfig, fuc)
    })
  } else if (config.children) {
    config.children.forEach((subConfig) => {
      deepTravel(subConfig, fuc)
    })
  } else {
    fuc(config)
  }
}

const homeRouter = []

deepTravel(stageConfig, (viewConfig) => {
  const viewRouter = {}
  viewRouter.path = viewConfig.route
  viewRouter.name = viewConfig.name
  viewRouter.component = () => import(`@/${viewConfig.filePath}`)
  viewRouter.meta = {
    breadcrumb: viewConfig.breadcrumb
  }
  homeRouter.push(viewRouter)
})

export default homeRouter
